package com.gxc.webcore.util;

import org.springframework.context.ApplicationContext;

public class ContextUtil {

	private static String applicationRealPath;
	private static ApplicationContext applicationContext;

	public static String getApplicationRealPath() {
		return applicationRealPath;
	}

	public static void setApplicationRealPath(String applicationRealPath) {
		ContextUtil.applicationRealPath = applicationRealPath;
	}

	public static ApplicationContext getApplicationContext() {
		return applicationContext;
	}

	public static void setApplicationContext(
			ApplicationContext applicationContext) {
		ContextUtil.applicationContext = applicationContext;
	}

	/**
	 * 获取bean
	 * 
	 * @param beanName
	 * @return
	 */
	public static Object getBean(String beanName) {
		try {
			return applicationContext.getBean(beanName);
		} catch (Exception e) {
			return null;
		}
	}

	/**
	 * 获取bean
	 * 
	 * @param clazz
	 * @return
	 */
	public static Object getBean(Class<?> clazz) {
		try {
			return applicationContext.getBean(clazz);
		} catch (Exception e) {
			return null;
		}
	}

}
